package com.demo2do.fms.admin.web.controller.query;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo2do.core.entity.result.HttpResult;
import com.demo2do.fms.admin.service.business.ShipmentService;
import com.demo2do.fms.entity.business.Shipment;

/**
 *
 * @author Ark
 *
 */
@Controller
@RequestMapping("/shipments")
public class ShipmentQueryController {

    @Autowired
    private ShipmentService shipmentService;
    
    /**
     * 调度指令号，查询调度指令组号
     * 
     * @param loadNumber
     * @param orgIds
     * @return
     */
    @RequestMapping(value = "/query", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody HttpResult onQuery(@RequestParam("loadNumber") String loadNumber,
                                            @RequestParam("orgIds") List<Long> orgIds) {
        
        HttpResult httpResult = new HttpResult();
        
        Shipment shipment = shipmentService.loadShipment(loadNumber, orgIds);

        if (shipment != null) {
            
            httpResult.success().data("loadGroupNumber", shipment.getLoadGroupNumber());
            
            return httpResult;
            
        }
        
        return httpResult.fail("400").message("输入信息有误");
        
    }
    
}
